package com.example.demo.Config;
import com.example.demo.Common.PublicValue;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
//实现接口
@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
       //判断用户登录
        HttpSession session= request.getSession(false);
        System.out.println(session);
        if(session!=null && session.getAttribute(PublicValue.SessionValue)!=null){
            return true;
        }else{
            response.sendRedirect("/blog-login.html");
            return false;
        }
    }
}
